﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EnterpriseFund.Common;
namespace EnterpriseFund.Controllers
{
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class SKZLManagerController : AdminBaseController
    {
        [AuthorityActionFilter("m_DM_SKZL", Order = 1)]
        [LogPageActionFilter("税款种类管理", Order = 2)]
        public ActionResult Index()
        {

            List<Model.DM_SKZL> codeNameList = new List<Model.DM_SKZL>();
            ViewData["blcode"] = true;
            BLL.DM_SKZL codeNameBll = new BLL.DM_SKZL();
            codeNameList = codeNameBll.GetModelList("");
            return View(codeNameList);
        }
        /// <summary>
        /// 编码树相关调用方法 主要用于刷新
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult SKZLManageListPartial()
        {
            BLL.DM_SKZL codeNameBll = new BLL.DM_SKZL();
            List<Model.DM_SKZL> codeNameList = new List<Model.DM_SKZL>();
            codeNameList = codeNameBll.GetModelList("");
            ViewData["blcode"] = true;
            return PartialView("SKZLManageListPartial", codeNameList);
        }
        /// <summary>
        /// 编码增加修改
        /// </summary>
        /// <param name="codeNo">编码</param>
        /// <returns>视图</returns>
        public ActionResult DM_SKZLEdit(string SKZL_DM)
        {
            Model.DM_SKZL codeNameObj = new Model.DM_SKZL();
            ViewData["blcodeNo"] = true;
            BLL.TaxClass taxClassBLL = new BLL.TaxClass();
            ViewData["TaxClassList"] = taxClassBLL.GetModelList("");
            if (null != SKZL_DM)
            {
                SKZL_DM = Fetch.estimateString(SKZL_DM, CheckGetEnum.Safety);
                BLL.DM_SKZL codeNameBll = new BLL.DM_SKZL();
                codeNameObj = codeNameBll.GetModel(SKZL_DM);
                if (null == codeNameObj)
                {
                    codeNameObj = new Model.DM_SKZL();
                }
                else
                {
                    ViewData["blcodeNo"] = false;
                }
            }
            return View(codeNameObj);
        }
        /// <summary>
        /// 删除编码数据
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <returns>是否删除成功</returns>
        public string DelSKZL(string SKZL_DM)
        {
            string str = string.Empty;
            if (null != SKZL_DM)
            {
                SKZL_DM = Fetch.estimateString(SKZL_DM, CheckGetEnum.Safety);
                BLL.DM_SKZL codeNameBll = new BLL.DM_SKZL();
                try
                {
                    codeNameBll.Delete(SKZL_DM);
                    str = "ok";
                }
                catch (Exception)
                {
                    str = "error";
                }
            }
            return str;
        }
        /// <summary>
        /// 编码保存
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <param name="codeName">编码名字</param>
        /// <returns>是否修改成功</returns>
        public string SKZLSave(string SKZL_DM, string SKZL_MC, string GS_SKZL_MC, string YXBZ, bool isAdd)
        {
            string str = string.Empty;

            SKZL_DM = Fetch.estimateString(SKZL_DM, CheckGetEnum.Safety);
            SKZL_MC = Fetch.estimateString(SKZL_MC, CheckGetEnum.Safety);
            GS_SKZL_MC = Fetch.estimateString(GS_SKZL_MC, CheckGetEnum.Safety);
            YXBZ = Fetch.estimateString(YXBZ, CheckGetEnum.Safety);
            BLL.DM_SKZL codeNameBll = new BLL.DM_SKZL();
            if (isAdd)//增加时判断编码是否已存在
            {
                if (codeNameBll.Exists(SKZL_DM))
                {
                    return "exists";
                }
            }

            Model.DM_SKZL codeNameObj = new Model.DM_SKZL();
            codeNameObj.SKZL_DM = SKZL_DM;
            codeNameObj.SKZL_MC = SKZL_MC;
            codeNameObj.GS_SKZL_MC = GS_SKZL_MC;
            codeNameObj.YXBZ = YXBZ;

            try
            {
                if (isAdd)
                {
                    codeNameBll.Add(codeNameObj);
                }
                else
                {
                    codeNameBll.Update(codeNameObj);
                }
                str = "ok";

            }
            catch (Exception)
            {

                str = "error";
            }

            return str;
        }
    }
}
